


let vm = new Vue({
    el: ".warehouse5",
    data: {
        loading: false,
        tableData: [],
        tfootContent: {},
        test: [],
        allpages: 0,
    },
    methods: {

        getDate() {
            this.loading = true;
            let startTime = (new Date()).getTime();
            let par = {
                code: leiku.GetUrlParam("code"),
                pg: leiku.GetUrlParam("pg"),
                bm: leiku.GetUrlParam("bm"),
                cangwei: leiku.GetUrlParam("cangwei"),
                jianxie: leiku.GetUrlParam("jianxie"),
                neibupici: leiku.GetUrlParam("neibupici"),
                cangku: leiku.GetUrlParam("cangku"),
            }

            leiku.post('http://dongtai.fsslpc.com/api/2020092336671971', par, res => {
                let data = res.data;
                console.log(data)
                if (data.a.length) {
                    this.tableData = data.a;
                    this.tfootContent = data.b[0];

                    //this.test = data.a.slice(1, 500);

                    this.printPageing();

                    $(".count").text($(".container").find("table").length);
                    this.loading = false;

                    let endTime = (new Date()).getTime();
                    console.log('请求花费：', (endTime - startTime) / 1000, '秒');
                }

            })
        },
        printPageing() {
            const printHeight = 250;

            this.tableData.forEach(item => {
                $("#CS").html(`
                    <tr class="tdStyle">
                    <td>${item.name || ''}</td>
                    <td>${item.bm || ''}</td>
                    <td style="white-space:nowrap">${item.cktx || ''}</td>
                    <td>${item.cwtx || ''}</td>
                    <td>${item.jianxie || ''}</td>
                    <td>${item.pg || ''}</td>
                    <td>${item.zibianganghao || ''}</td>
                    <td>${item.xcma || ''}</td>
                    <td>${item.xcpishu || ''}</td>
                    <td>${item.remark || ''}</td>
                </tr>
                `)
                let csendTr = $("#CS").outerHeight();
                let tbLen = $(".container").find("table").length - 1;
                let currentTable = $(".container").find("table").eq(tbLen);

                let Num = 297;
                
                /* console.log(currentTable.outerHeight(true), new leiku.unitConversion().mmConversionPx(Num)) */
                let tbH = currentTable.outerHeight(true);
                let countH = new leiku.unitConversion().mmConversionPx(Num)
                if (tbH < countH && (parseInt(countH - tbH) > csendTr + 22)) {
                    currentTable.find("tbody").append(
                        `
                        <tr class="tdStyle">
                            <td>${item.name || ''}</td>
                            <td>${item.bm || ''}</td>
                            <td style="white-space:nowrap">${item.cktx || ''}</td>
                            <td>${item.cwtx || ''}</td>
                            <td>${item.jianxie || ''}</td>
                            <td>${item.pg || ''}</td>
                            <td>${item.zibianganghao || ''}</td>
                            <td>${item.xcma || ''}</td>
                            <td>${item.xcpishu || ''}</td>
                            <td>${item.remark || ''}</td>
                        </tr>
                    `)
                } else {
                    $("#CS").html('')
                    let str =
                        `<div class="cut"></div>
                        <table style="width:100%;max-height:297mm;overflow:hidden">
                            <thead class="header">
                                <tr>
                                    <th colspan="12"  style="padding-top:20px;font-size: 20px;position: relative;border-color: transparent;border-bottom-color: black;">
                                        <span>仓库资料查询报表</span>
                                        <span style="position: absolute; right:20px;bottom:0px; font-size: 15px;">
                                        <span class="page">第${tbLen + 2}页，</span>
                                        共<span class="count"></span>页                                                   
                                        </span>
                                    </th>
                                </tr>
                                <tr class="thStyle">
                                    <th style="width: 21mm;">品名+轴号</th>
                                    <th style="width: 21mm;">部门</th>
                                    <th style="width: 21mm;">仓库</th>
                                    <th style="width: 21mm;">仓位</th>
                                    <th style="width: 21mm;">加工厂</th>
                                    <th style="width: 21mm;">浆紗缸号</th>
                                    <th style="width: 21mm;">自编批次</th>
                                    <th style="width: 21mm;">现存码数</th>
                                    <th style="width: 21mm;">匹数</th>
                                    <th style="width: 21mm;">备注</th>
                                </tr>
                            </thead>
        
                            <tbody>
                            </tbody>
                                            
                            <tfoot class="tfStyle">
                                <td>总数量：</td>
                                <td>${this.tfootContent.sumxcma}</td>
                                <td>总件数：</td>
                                <td>${this.tfootContent.sumxcpishu}</td>
                                <td colspan="1">制表人：</td>
                                <td colspan="2">${this.tfootContent.printer}</td>
                                <td colspan="2">制表日期：</td>
                                <td>${this.tfootContent.printtime}</td>
                            </tfoot>
                        </table>
                    `;
                    $(".container").append(str);
                }
            })
            $('.cut').first().remove()
        },
        prints() {
            $(this.$refs.printPage).print({
                //stylesheet: "../css/warehouse_info5.css",
                globalStyles: true,
                mediaPrint: true,
                iframe: true,
            });

        }
    },
    mounted() {
        this.getDate();

    }
})